package com.yaorange.module.system.mapper;

import com.yaorange.pojo.SysRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SysRoleMapper {
    @Select("select * from sys_role")
    List<SysRole> findAll();

    @Select("select * from sys_role where id=#{id}")
    SysRole findById(Long id);

    void save(SysRole sysRole);

    @Update("update sys_role set role_name=#{roleName},role_des=#{roleDes} where role_id=#{roleId}")
    void update(SysRole roleDetails);

    @Delete("delete from sys_role where role_id=#{id}")
    void deleteById(Long id);

    @Select("select perm_id from sys_role_permission where role_id=#{roleId}")
    List<Long> findPermissionsByRoleId(Long roleId);

    @Delete("delete from sys_role_permission where role_id= #{roleId}")
    void deleteByRoleId(Long roleId);

    void grantPermissions(List<Long> permissionIds, Long roleId);

    @Delete("delete from sys_role where role_id in (${roleIds})")
    void deleteByIds(List<Long> roleIds);
}
